//
//  ZSBReadJsonDate.m
//  HCNewGoldFinger
//
//  Created by zjhcsoft on 14-10-11.
//  Copyright (c) 2014年 zjhcsoftios. All rights reserved.
//

#import "ZSBReadJsonDate.h"

#import "ZSBContactInfo.h"
#import <MJExtension/MJExtension.h>


@implementation ZSBReadJsonDate


//联系人界面公司列表
+ (NSMutableArray *)readJSonStringContactAreaList:(NSString *)dataStr andLevel:(NSInteger)level
{
    // 入参判断
    if (dataStr.length == 0) return nil;
    
    
    // 响应状态码
//    NSInteger status = [[[dataStr mj_JSONObject] objectForKey:ZSBReqCode] integerValue];
    // 出错情况
//    if (status != ZSBReqSuccess) return nil;
    // 根节点
    NSDictionary *resultDic1 = [[dataStr mj_JSONObject] objectForKey:@"body"];
    if (!resultDic1) {
        return nil;
    }
    NSMutableArray *returnArr = [[NSMutableArray alloc] init];
    if ([resultDic1 objectForKey:@"companyAndContactsVo"] && [[resultDic1 objectForKey:@"companyAndContactsVo"] isKindOfClass:[NSDictionary class]]) {
        NSDictionary *dic = [resultDic1 objectForKey:@"companyAndContactsVo"];
        if ([dic objectForKey:@"companyInsideProxyList"] && [[dic objectForKey:@"companyInsideProxyList"] isKindOfClass:[NSArray class]]) {
            NSArray *array = [dic objectForKey:@"companyInsideProxyList"];
            ZSBContactInfo *provinceContactInfo = [[ZSBContactInfo alloc] init];
            provinceContactInfo.sysCompanyRowId = [NSNumber numberWithLong:3772265];
            provinceContactInfo.companyName = @"省公司";
            provinceContactInfo.contactType = ZSBContactTypeCompany;
            provinceContactInfo.level = -1;
            provinceContactInfo.isExpansion = YES;
            [returnArr addObject:provinceContactInfo];
            for (int i = 0; i < array.count; i++) {
                if ([[array objectAtIndex:i] isKindOfClass:[NSDictionary class]]) {
                    NSDictionary *dic = [array objectAtIndex:i];
                    ZSBContactInfo *contactInfo = [[ZSBContactInfo alloc] init];
                    if ([dic objectForKey:@"companyId"]) {
                        contactInfo.companyId = [dic objectForKey:@"companyId"];
                    }
                    if ([dic objectForKey:@"sysCompanyRowId"]) {
                        contactInfo.sysCompanyRowId = [dic objectForKey:@"sysCompanyRowId"];
                    }
                    if ([dic objectForKey:@"companyName"]) {
                        contactInfo.companyName = [dic objectForKey:@"companyName"];
                    }
                    if ([dic objectForKey:@"userName"]) {
                        contactInfo.userName = [dic objectForKey:@"userName"];
                    }
                    contactInfo.contactType = ZSBContactTypeCompany;
                    contactInfo.level = level;
                    if (contactInfo.level == -1) {
                        contactInfo.isExpansion = YES;
                    }
                    [returnArr addObject:contactInfo];
                }
            }
        }
    }
    return returnArr;
}
//联系人界面
+ (NSMutableArray *)readJSonStringContactInfoList:(NSString *)dataStr andLevel:(NSInteger)level
{
    // 入参判断
    if (dataStr.length == 0) return nil;
    
    
    // 响应状态码
//    NSInteger status = [[[dataStr mj_JSONObject] objectForKey:ZSBReqCode] integerValue];
    // 出错情况
//    if (status != ZSBReqSuccess) return nil;
    // 根节点
    NSDictionary *resultDic1 = [[dataStr mj_JSONObject] objectForKey:@"body"];
    if (!resultDic1) {
        return nil;
    }
    NSMutableArray *returnArr = [[NSMutableArray alloc] init];
    
    if ([resultDic1 objectForKey:@"companyAndContactsVo"] && [[resultDic1 objectForKey:@"companyAndContactsVo"] isKindOfClass:[NSDictionary class]]) {
        NSDictionary *dic = [resultDic1 objectForKey:@"companyAndContactsVo"];
        if ([dic objectForKey:@"companyInsideProxyList"] && [[dic objectForKey:@"companyInsideProxyList"] isKindOfClass:[NSArray class]]) {
            NSArray *array = [dic objectForKey:@"companyInsideProxyList"];
            for (int i = 0; i < array.count; i++) {
                if ([[array objectAtIndex:i] isKindOfClass:[NSDictionary class]]) {
                    NSDictionary *dic = [array objectAtIndex:i];
                    ZSBContactInfo *contactInfo = [[ZSBContactInfo alloc] init];
                    if ([dic objectForKey:@"companyId"]) {
                        contactInfo.companyId = [dic objectForKey:@"companyId"];
                    }
                    if ([dic objectForKey:@"sysCompanyRowId"]) {
                        contactInfo.sysCompanyRowId = [dic objectForKey:@"sysCompanyRowId"];
                    }
                    if ([dic objectForKey:@"companyName"]) {
                        contactInfo.companyName = [dic objectForKey:@"companyName"];
                    }
                    if ([dic objectForKey:@"userName"]) {
                        contactInfo.userName = [dic objectForKey:@"userName"];
                    }
                    contactInfo.contactType = ZSBContactTypeCompany;
                    contactInfo.level = level;
                    [returnArr addObject:contactInfo];
                }
            }
        }
    }
    if ([resultDic1 objectForKey:@"companyAndContactsVo"] && [[resultDic1 objectForKey:@"companyAndContactsVo"] isKindOfClass:[NSDictionary class]]) {
        NSDictionary *dic = [resultDic1 objectForKey:@"companyAndContactsVo"];
        if ([dic objectForKey:@"userInsideProxyList"] && [[dic objectForKey:@"userInsideProxyList"] isKindOfClass:[NSArray class]]) {
            NSArray *array = [dic objectForKey:@"userInsideProxyList"];
            for (int i = 0; i < array.count; i++) {
                if ([[array objectAtIndex:i] isKindOfClass:[NSDictionary class]]) {
                    NSDictionary *dic = [array objectAtIndex:i];
                    ZSBContactInfo *contactInfo = [[ZSBContactInfo alloc] init];
                    if ([dic objectForKey:@"companyId"]) {
                        contactInfo.companyId = [dic objectForKey:@"companyId"];
                    }
                    if ([dic objectForKey:@"sysCompanyRowId"]) {
                        contactInfo.sysCompanyRowId = [dic objectForKey:@"sysCompanyRowId"];
                    }
                    if ([dic objectForKey:@"companyName"]) {
                        contactInfo.companyName = [dic objectForKey:@"companyName"];
                    }
                    if ([dic objectForKey:@"userName"]) {
                        contactInfo.userName = [dic objectForKey:@"userName"];
                    }
                    if ([dic objectForKey:@"sysUserRowId"]) {
                        contactInfo.sysUserRowId = [dic objectForKey:@"sysUserRowId"];
                    }
                    if ([dic objectForKey:@"headImgUrl"]) {
                        contactInfo.headImgUrl = [dic objectForKey:@"headImgUrl"];
                    }
                    if ([dic objectForKey:@"staName"]) {
                        contactInfo.staName = [dic objectForKey:@"staName"];
                    }
                    contactInfo.contactType = ZSBContactTypeUser;
                    contactInfo.level = level;
                    [returnArr addObject:contactInfo];
                }
            }
        }
    }
    return returnArr;
}
//联系人界面
+ (NSNumber *)readJSonStringContactInfoListMyCompanyID:(NSString *)dataStr
{
    // 入参判断
    if (dataStr.length == 0) return nil;
    
    
    // 响应状态码
//    NSInteger status = [[[dataStr  mj_JSONObject] objectForKey:ZSBReqCode] integerValue];
    // 出错情况
//    if (status != ZSBReqSuccess) return nil;
    // 根节点
    NSDictionary *resultDic1 = [[dataStr mj_JSONObject] objectForKey:@"body"];
    if (!resultDic1) {
        return nil;
    }
    if ([resultDic1 objectForKey:@"companyAndContactsVo"] && [[resultDic1 objectForKey:@"companyAndContactsVo"] isKindOfClass:[NSDictionary class]]) {
        NSDictionary *dic = [resultDic1 objectForKey:@"companyAndContactsVo"];
        if ([dic objectForKey:@"userTopCompanyId"] && [[dic objectForKey:@"userTopCompanyId"] isKindOfClass:[NSNumber class]]) {
            return [dic objectForKey:@"userTopCompanyId"];
        }
    }
    
    return [NSNumber numberWithInt:0];
}

@end
